package com.sx.gongzhong.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.gongzhong.R;
import com.sx.gongzhong.activity.MyLettersDetailActivity;
import com.sx.gongzhong.model.LetterBean;
import com.sx.gongzhong.model.PhotoBean;
import com.sx.gongzhong.net.ServiceFactory;

import java.util.List;


/**我的信访举报
 * Created by admin on 2018/1/5.
 */

public class MyLettersAdapter extends BaseQuickAdapter<LetterBean,BaseViewHolder> {

    private Context context;

    public MyLettersAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<LetterBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final LetterBean item) {
        helper.setText(R.id.tv_Content,item.getContent());
        helper.setText(R.id.tv_Time,item.getReportTime());
        ImageView imageView = helper.getView(R.id.imageView);
        final RequestOptions options = new RequestOptions()
                .centerCrop()
                .placeholder(R.mipmap.img_fail)
                .error(R.mipmap.img_fail);
        if (item.getFiles() != null && item.getFiles().size() > 0) {
            imageView.setVisibility(View.VISIBLE);
            PhotoBean bean=item.getFiles().get(0);
            String type=bean.getFileType();
            if ("video".equalsIgnoreCase(type)) {
                imageView.setImageResource(R.mipmap.img_videos);
            }else if ("audio".equalsIgnoreCase(type)) {
                imageView.setImageResource(R.mipmap.img_audio);
            } else {//图片
                Glide.with(context)
                        .load(ServiceFactory.getUrl(bean.getPath()))
                        .apply(options)
                        .into(imageView);
            }
        }else {
            imageView.setVisibility(View.GONE);
        }
        helper.getView(R.id.rl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context,MyLettersDetailActivity.class)
                        .putExtra("letterBean",item));
            }
        });
    }
}
